﻿; (function (window, undefined, $) {

    $(document).ready(function () {

        var gridopt = {
            url: options.listUrl,
            colModel: [
                   
                    { display: '编号', name: 'New_ID', width: "3%", sortable: true, hide: false, align: 'left', iskey: true },
                    { display: 'Id', name: 'Id', width: "3%", sortable: true, hide: true, align: 'left', iskey: true },
                    { display: '状态', name: 'Status', width: "5%",hide:true, sortable: false, align: 'left' },
                    { display: '标题', name: 'MessTitle', width: "15%", sortable: false, align: 'left' },
                    { display: '类别', name: 'ClassId', width: "15%", sortable: false, align: 'left',process: proClass },
                    { display: '留言时间', name: 'CreateTime', width: "15%", sortable: false, align: 'left' },
                    //{ display: '回复人', name: 'MemberName', width: "15%", sortable: false, align: 'left' },
                    { display: '操作', name: 'Id', width: "15%", sortable: false, align: 'center', process: processOp }
              //{ display: '用户名', name: 'MemberId', width: "6.25%", sortable: false, align: 'left' },
            //{ display: '状态', name: 'Status', width: "6.25%", sortable: false, align: 'left' },
            ],  
            sortname: "CreateTime",
            sortorder: "DESC",
            title: false,
            rp: 15,
            usepager: true,
            showcheckbox: false
        };
        var xjgrid = new xjGrid("gridlist", gridopt);
        function processOp(value, cell) {
            var ops = [];
            if (cell[2] == 0) {
                ops.push("&nbsp;<a title='查看' href='javascript:;'  onclick=\"util.See('", value, "')\"><i class='fa fa-edit' ></i>查看</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            } else if (cell[2] == 1 || cell[2] == 2) {
                ops.push("&nbsp;<a title='查看' href='javascript:;'  onclick=\"util.See('", value, "')\"><i class='fa fa-edit' ></i>查看</a>");
                ops.push("&nbsp;<a title='编辑' href='javascript:;'  onclick=\"util.Edit('", value, "')\"><i class='fa fa-edit' ></i>编辑</a>");
                ops.push("&nbsp;&nbsp;<a title='删除' class='abtn' href='javascript:;'  onclick=\"util.Delete('", value, "','", cell[1], "')\"><i class='fa fa-trash-o' ></i>删除</a>");
            }

            return ops.join("");
        }
        function proClass(value, cell) {
            if (value==1) {
                return '安全问题';
            } else if (value==2) {
                return '投标问题';
            } else if (value == 3) {
                return '关于汇金行';
            } else if (value == 4) {
                return '其他';
            }
        }
        //
        //function OpMessage(value, cell)
        //{
        //    var ops = [];
        //    if (cell[2] == 0) {
        //        ops.push("&nbsp;<a  href='javascript:;'  onclick=\"util.See('", value, "')\"><i class='fa fa-edit' >"+cell[4].value+"</i></a>");
        //    } else {
        //        ops.push("&nbsp;<a  href='javascript:;'><i class='fa fa-edit' >" + cell[4].value + "</i></a>");
        //    }
        //    return ops.join("");
        //}
        $("#formQuery").submit(function () {
            xjgrid.Query(this);
            return false;
        });
        $("#btnSearch").click(function () {
            $("#formQuery").submit();
        });
        $("#btnAdd").click(function (e) {
            var url = options.editUrl;
            location.href = url;
        });
        util.See = function (id) {
            var url = options.ShowUrl + "/" + id;
            location.href = url;
        };

        util.Edit = function (id) {
            var url = options.editUrl + "/" + id;
            location.href = url;
        };

        util.Delete = function (id, name) {
            if (!confirm("您确定要执行删除操作吗？")) {
                return false;
            }
            $.post(options.deleteUrl + "/" + id, { id: id },
                  function (res) {
                      if (res.Status > 0) {
                          alert("操作成功！");
                          xjgrid.Reload();
                      }
                      else {
                          alert("操作失败！");
                      }
                  },
                  "json"
            );
        };
    });

})(window, undefined, jQuery);
